Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TT-13507] Fix for custom domains with substring listen path #6705

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

andrei-tyk
Copy link
Contributor

@andrei-tyk andrei-tyk commented Nov 14, 2024

User description

Actual fix for domain matching edge case related to substring listen paths. Fixed the sorting function for the listen paths and added some unit tests.

Extra: httpbin service not working on macos with apple silicon; now it does

Description

Related Issue

Motivation and Context

How This Has Been Tested

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring or add test (improvements in base code or adds test coverage to functionality)

Checklist

  • I ensured that the documentation is up to date
  • I explained why this PR updates go.mod in detail with reasoning why it's required
  • I would like a code coverage CI quality gate exception and have explained why

PR Type

Bug fix, Configuration changes


Description

  • Fixed the domain sorting logic in the API loader by changing the comparison from domain length to lexicographical order to ensure correct domain matching.
  • Updated the Docker configuration for the httpbin service to specify the platform as linux/amd64, addressing compatibility issues on macOS with Apple Silicon.

Changes walkthrough 📝

Relevant files
Bug fix
api_loader.go
Fix domain sorting logic in API loader                                     

gateway/api_loader.go

  • Modified sorting logic for API specs by domain.
  • Changed comparison from domain length to lexicographical order.
  • +1/-1     
    Configuration changes
    httpbin.yml
    Specify platform for httpbin service in Docker configuration

    docker/services/httpbin.yml

    • Added platform specification for httpbin service.
    +1/-0     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    @buger
    Copy link
    Member

    buger commented Nov 14, 2024

    💔 The detected issue is not in one of the allowed statuses 💔

    Detected Status DoD Check
    Allowed Statuses In Dev,In Code Review,Ready for Testing,In Test,In Progress,In Review ✔️

    Please ensure your jira story is in one of the allowed statuses

    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Domain Sorting Logic
    The change from length-based to lexicographical domain sorting may introduce issues with domain matching where subdomains are involved. This needs thorough testing to ensure no regression or unexpected behavior in domain matching.

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Best practice
    Ensure domain comparison is case-insensitive to avoid inconsistencies

    Replace the string comparison for domains with a case-insensitive comparison to
    ensure consistent behavior regardless of case variations.

    gateway/api_loader.go [938]

    -return specs[i].Domain > specs[j].Domain
    +return strings.ToLower(specs[i].Domain) > strings.ToLower(specs[j].Domain)
    Suggestion importance[1-10]: 7

    Why: The suggestion to make domain comparison case-insensitive is valid and improves the robustness of the sorting logic by ensuring consistent behavior across different case variations.

    7
    Possible issue
    Check compatibility of the specified platform with deployment environments

    Verify the compatibility of the specified platform 'linux/amd64' with all potential
    deployment environments to ensure there are no runtime issues on different
    architectures.

    docker/services/httpbin.yml [5]

    -platform: linux/amd64
    +platform: linux/amd64  # Ensure compatibility with deployment environments
    Suggestion importance[1-10]: 1

    Why: The suggestion is a general reminder to check compatibility, which is a good practice but does not directly improve or modify the code. It's more of a cautionary note than a code improvement.

    1

    Copy link
    Contributor

    API Changes

    no api changes detected

    @andrei-tyk andrei-tyk changed the title [TT-13507] possible fix for domain matching and httpbin not working on… [TT-13507] Fix for custom domains with substring listen path Nov 18, 2024
    Copy link
    Member

    @lghiur lghiur left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    LGTM, this implements the agreed algo, where all paths are order descending by listen path, but those API that have custom domain will be placed in front of those without.

    Copy link

    sonarcloud bot commented Nov 20, 2024

    Quality Gate Failed Quality Gate failed

    Failed conditions
    0.0% Coverage on New Code (required ≥ 80%)
    C Reliability Rating on New Code (required ≥ A)

    See analysis details on SonarQube Cloud

    Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    3 participants